Ext.define('AM.view.LeaderJobView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.leaderJobView',
		store : 'LeaderJobStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"     //"SINGLE"/"SIMPLE"/"MULTI"
	       
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
	        xtype: 'pagingtoolbar',
	        dock: 'bottom',
	        store : 'LeaderJobStore',
	        displayInfo: true
        }],
         plugins: [{
            ptype: 'rowexpander',
            rowBodyTpl : new Ext.XTemplate(
                '<p><b>要求:</b> {jobRequirement}</p>'

            
            )
        }],
		columns: [
			       // { text: '序号', width:50,align:'center', xtype: 'rownumberer'},
		            {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { text: '名称', dataIndex: 'name', width:100,align:'center'},
			        { text: '所属项目', dataIndex:'tastJob.name', width:100,align:'center'},
			        { text: '开始时间', dataIndex: 'startdate', width:110,align:'center',xtype: 'datecolumn',   format:'Y-m-d'},
			        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:110,align:'center',xtype: 'datecolumn',   format:'Y-m-d' },
			        { text: '状态', dataIndex: 'state',  width:90,align:'center',renderer: function(value){
								 if (value === 2) {
										 return '<span style="color:green;">办理中</span>';
								 }if (value ===1) {
										  return '<span style="color:purple;">未办理</span>'; 
								 }if (value === 3) {
										 return '<span style="color:red;">结束</span>';
								 }	
						}					 
			        },
			        { text: '要求', dataIndex: 'jobRequirement', width:200,align:'center'},
			        { text: '操作', dataIndex: 'id',width:220,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){			        	
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='banLiLeaderJob("+record.get('id')+")'>办理任务</a>&nbsp;&nbsp;&nbsp;&nbsp;" +     
                            "<a href='javascript:void("+record.get('id')+");' class='alarm_detail'onclick='wanchengLeaderJob("+record.get('id')+")'>完成任务</a>&nbsp;&nbsp;&nbsp;&nbsp;"+ 
                            "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='loadfujian("+record.get('id')+")'>下载附件</a>&nbsp;&nbsp;&nbsp;&nbsp;"    
                            "</div>";     
         					return resultStr;  
			       		  }
         	    	}
			     ]

})
 function banLiLeaderJob(id){
 	
	   	  	Ext.Ajax.request({
					url : 'DetailJobAction_banli',
					success : function() {
						var myform1= new Ext.form.Panel({
									        layout : "form",
									        labelWidth : 200,
									        items: [{
											        layout : "column",
											        border : false,
											        	items: [{
													        	columnWidth :.80,
																layout : "form",
																border : false,
																labelWidth : 30,
													   			items: [{
													   				    xtype : "textarea",
													   				    fieldLabel: '回复内容',
													   				    labelAlign :"right",
															            name: 'huifu',
															            width:200
															        }]		        	
												        	}]
									        	 }]
						 	 })
							var win = new Ext.Window({
									title : "添加回复",
									width : 500,
									height : 200,
									frame:true,
									layout:'fit',
								    items :[myform1],
									buttons : [
											  {text : "确定",
													handler : function() {
														win.getComponent(0).getForm().submit({
																	    url : 'DetailJobAction_huifu',
																	    success : function() {
																		Ext.Msg.alert('提示', '回复成功');
																		win.close();
																	},
																	failure : function() {
																		Ext.Msg.alert('错误', '回复失败');
																	},
																	waitMsg : "请稍后，正在保存。。。。",
																params : {
																			id:id	
																			}
															});
													}
												}, {
													text : "重置",
													handler : function() {
														win.getComponent(0).getForm().reset();
													}
												}, {
													text : "取消",
													handler : function() {
																		win.close();
																	
													}
										}]
					 	}).show();
					
			    myJobView=Ext.create('AM.view.LeaderJobView');
			    myJobView.getStore().reload();							 
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "项目正在办理中！");
				},
				params : {
						id:id	
					}
		});	
 }
    //完成工作
  function wanchengLeaderJob(id){
   	  	Ext.Ajax.request({
				url : 'DetailJobAction_wancheng',
				success : function() {
					  myJobView=Ext.create('AM.view.LeaderJobView');
					 myJobView.getStore().reload();						 
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "项目还未办理！");
				},
				params : {
						id:id	
					}
		});	
 }
 //下载附件
function loadfujian(id){
	    var jobid=id;
	 	Ext.Ajax.request({
				url : 'DetailJobAction_download',
				success : function() {
						 window.location.href ="DetailJobAction_downloadfujian?id="+id+"";
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "无附件可以下载！");
				},
				params : {
						id:jobid	
					}
		});		
	
	
	
}
